package com.joysuch.wwyt.list.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.joysuch.wwyt.core.common.ajax.ResultBean;
import com.joysuch.wwyt.list.bean.*;
import com.joysuch.wwyt.list.service.BpListBizService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author xiaoying
 * @since 2021-05-17
 */
@Slf4j
@RestController
@RequestMapping("/bp/list/bp-list-biz")
@Api(tags = "清单管理-业务管理")
public class BpListBizController {


    @Autowired
    private BpListBizService bpListBizService;

    @PostMapping("/pageAll")
    @ApiOperation(value = "清单管理列表(分页）", response = BpListBizListBean.class)
    public ResultBean pageAll(@RequestBody @Validated BpListBizQueryBean queryBean) {

        Page<BpListBizListBean> page = new Page<>(queryBean.getPage() + 1, queryBean.getSize());
        IPage<BpListBizListBean> pageData = bpListBizService.pageAll(page, queryBean);

        return ResultBean.pageData(pageData.getRecords(), pageData.getTotal());

    }

    @PostMapping("/myPage")
    @ApiOperation(value = "我的清单列表(分页）", response = BpListBizListBean.class)
    public ResultBean myPage(@RequestBody BpListBizQueryBean queryBean) {

        Page<BpListBizListBean> page = new Page<>(queryBean.getPage() + 1, queryBean.getSize());
        IPage<BpListBizListBean> pageData = bpListBizService.myPage(page, queryBean);

        return ResultBean.pageData(pageData.getRecords(), pageData.getTotal());
    }


    @GetMapping("/getById")
    @ApiOperation(value = "获取文档清单(根据类型Id）", response = BpListBizDetailBean.class)
    public ResultBean getById(@RequestParam Long id) {
        BpListBizDetailBean bpListBiz = bpListBizService.getDetailById(id);
        return ResultBean.success(bpListBiz);
    }

    @GetMapping("/work/getById")
    @ApiOperation(value = "获取清单工作详情", response = BpListBizDetailBean.class)
    public ResultBean getByWorkId(@RequestParam Long id) {
        BpListBizWorkDetailBean bpListWorkBiz = bpListBizService.getDetailByWorkId(id);
        return ResultBean.success(bpListWorkBiz);
    }

    @RequiresPermissions("bp:list:bp-list-biz:delete")
    @GetMapping("/deleteById")
    @ApiOperation(value = "删除文档清单(根据类型Id）")
    public ResultBean deleteById(@RequestParam Long id) {
        bpListBizService.deleteById(id);
        return ResultBean.defaultSuccessResult();
    }

    @RequiresPermissions("bp:list:bp-list-biz:save")
    @PostMapping("/save")
    @ApiOperation(value = "保存文档清单", response = BpListBizEditBean.class)
    public ResultBean save(@RequestBody BpListBizEditBean bean) {
        return bpListBizService.save(bean);
    }

    @RequiresPermissions("bp:list:bp-list-biz:saveUploadWork")
    @PostMapping("/saveUploadWork")
    @ApiOperation(value = "保存清单上传的工作", response = BpListBizUploadWorkEditBean.class)
    public ResultBean saveUploadWork(@RequestBody BpListBizUploadWorkEditBean bean) {
        return bpListBizService.saveUploadWork(bean);
    }

    @PostMapping("/work/pageAll")
    @ApiOperation(value = "清单管理列表(分页）", response = BpListBizUploadWorkBean.class)
    public ResultBean workPageAll(@RequestBody @Validated BpListBizWorkQueryBean queryBean) {

        Page<BpListBizUploadWorkBean> page = new Page<>(queryBean.getPage() + 1, queryBean.getSize());
        IPage<BpListBizUploadWorkBean> pageData = bpListBizService.workPageAll(page, queryBean);
        return ResultBean.pageData(pageData.getRecords(), pageData.getTotal());

    }
}

